package com.yidu.boss.sys.service.impl;


import com.yidu.boss.sys.dao.TrusteeMapper;
import com.yidu.boss.sys.domain.Trustee;
import com.yidu.boss.sys.domain.TrusteeExample;
import com.yidu.boss.sys.service.TrusteeService;
import com.yidu.boss.util.RandomString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Auther:si
 * @Date:2019/11/27
 * @Description:com.yidu.boss.sys.service.impl
 * @Version:1.0
 */
@Service
public class TrusteeServiceImpl implements TrusteeService {
    //定义dao层
    @Autowired
    private TrusteeMapper trusteeMapper;

    /**
     * 查询所有给基金表使用
     * @return
     */
    @Override
    public List<Trustee> selectAll() {
        return trusteeMapper.selectAll();
    }

    /**
     * 根据条件呢查询所有托管人
     * @param trusteeExample
     * @return
     */
    @Override
    public List<Trustee> selectByExample(TrusteeExample trusteeExample) {
        return trusteeMapper.selectByExample(trusteeExample);
    }

    /**
     * 模糊查询所有托管人信息
     * @param trustee
     * @return
     */
    @Override
    public List<Trustee> selectSomeByMore(String condition) {
        List<Trustee> trusteeList =trusteeMapper.selectSomeByMore(condition);
        return trusteeList;
    }

    /**
     * 添加
     * @param trustee
     * @return
     */
    @Override
    public int insertTrustee(Trustee trustee) {
        //Id
        trustee.setTrusteeId(RandomString.getUUID());
        int i =trusteeMapper.insertSelective(trustee);
        return i;
    }

    /**
     * 修改
     * @param trustee
     * @return
     */
    @Override
    public int updateTrustee(Trustee trustee) {
        //Example类
        TrusteeExample trusteeExample =new TrusteeExample();
        //获得托管人Id
       trusteeExample.or().andTrusteeIdEqualTo(trustee.getTrusteeId());
       //调用通过主键修改的方法
       int i =trusteeMapper.updateByPrimaryKeySelective(trustee);
        return i;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteTrustee(String id) throws DataAccessException {
        int i =trusteeMapper.deleteByPrimaryKey(id);
        return i ;
    }

}
